//
//  MBProgressHUD+NMAHud.m
//  优家
//
//  Created by ios-dev on 2017/12/18.
//  Copyright © 2017年 ios-dev. All rights reserved.
//

#import "MBProgressHUD+NMAHud.h"

@implementation MBProgressHUD (NMAHud)

-(void)showToastWithText:(NSString *)text
{
    [self show:NO];
    [self setMode:MBProgressHUDModeText];
    self.userInteractionEnabled = NO;
    self.bezelView.backgroundColor = [UIColor blackColor];
    self.detailsLabel.textColor = [UIColor whiteColor];
    self.detailsLabelText = text;
    self.detailsLabelFont = [UIFont boldSystemFontOfSize:16.];
    //    设置视图停留的时间
    [self hide:YES afterDelay:1.0];
}
-(void)showToastWithText:(NSString *)text isAutoHide:(BOOL)isAutoHide
{
    [self setMode:MBProgressHUDModeText];
    self.userInteractionEnabled = NO;
    self.bezelView.backgroundColor = [UIColor blackColor];
    self.detailsLabel.textColor = [UIColor whiteColor];
    self.detailsLabelText = text;
    self.detailsLabelFont = [UIFont boldSystemFontOfSize:14.];
    if (isAutoHide) {
        //    设置视图停留的时间
        [self hide:YES afterDelay:1.0];
    }
}

-(void)showToastWithText:(NSString *)text whileExecutingBlock:(dispatch_block_t)block
{
    [self setMode:MBProgressHUDModeText];
    self.userInteractionEnabled = NO;
    self.labelText = text;
    self.bezelView.backgroundColor = [UIColor blackColor];
    self.detailsLabel.textColor = [UIColor whiteColor];
    //    设置视图停留的时间
    dispatch_time_t time3s = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC));
    dispatch_after(time3s, dispatch_get_global_queue(0, 0), ^{
        [self hide:YES];
        dispatch_async(dispatch_get_main_queue(), ^{
            block();
        });
    });
}


+(MBProgressHUD *)showToastToView:(UIView *)view withText:(NSString *)text
{
    
    if(view==nil){
        view  =  [UIApplication sharedApplication].delegate.window;
        if(view==nil){
            view  =  [UIApplication sharedApplication].windows.lastObject;
        }
        
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    [hud showToastWithText:text];
    return hud;
}

+ (MBProgressHUD *)showToastWithText:(NSString *)text{
    return [self showToastToView:nil withText:text];
}


@end
